#
# Makefile for XPression 1.0
#
# Compiler: GCC 4.5.2
# Collaborators: @jlhervo @rlebobinnec 
#

GXX=g++
GCC=gcc

FLAGS=-lGL -lGLU -lglut -ll -ly
CFLAGS=-W -Wall

FLEX=flex
BISON=bison

OUT=xpression

BUILDER_DIR=xpression-builder
BUILDER=builder

CPP_SRC=$(wildcard *.cpp) $(wildcard */*.cpp)

SRC_FLEX=$(BUILDER_DIR)/$(BUILDER).lex
SRC_BISON=$(BUILDER_DIR)/$(BUILDER).y

PARAMETER=$(BUILDER_DIR)/$(BUILDER).tab.o $(BUILDER_DIR)/lex.yy.o $(CPP_SRC:.cpp=.o)

# Default
all: $(OUT)

$(OUT): $(PARAMETER)
	$(GCC) -o $@ $^ $(FLAGS)
		
# Bison 
$(BUILDER_DIR)/$(BUILDER).tab.h: $(SRC_BISON)
	$(BISON) $(SRC_BISON) -d -o $(BUILDER_DIR)/$(BUILDER).tab.c
	
$(BUILDER_DIR)/$(BUILDER).tab.c: $(SRC_BISON)
	$(BISON) $(SRC_BISON) -o $(BUILDER_DIR)/$(BUILDER).tab.c
		
$(BUILDER_DIR)/$(BUILDER).tab.o: $(BUILDER_DIR)/$(BUILDER).tab.c
	$(GCC) -c $(BUILDER_DIR)/$(BUILDER).tab.c -o $(BUILDER_DIR)/$(BUILDER).tab.o
	
# Flex 	
$(BUILDER_DIR)/lex.yy.c: $(SRC_FLEX)
	$(FLEX) -o $(BUILDER_DIR)/lex.yy.c $(SRC_FLEX)
	
$(BUILDER_DIR)/lex.yy.o: $(BUILDER_DIR)/lex.yy.c $(BUILDER_DIR)/$(BUILDER).tab.h
	$(GCC) -c $(BUILDER_DIR)/lex.yy.c -o $(BUILDER_DIR)/lex.yy.o
	
# Out Binaries (thx to @mvallerie)
main.o: main.cpp $(BUILDER_DIR)/$(BUILDER).tab.h
	$(GXX) -o $@ -c $< $(CFLAGS)	

# CPP Binaries
%.o: %.cpp
	$(GXX) -o $@ -c $< $(CFLAGS)

# Suppression Binaries
clean:
	rm -f *.o */*.o  $(BUILDER_DIR)/$(BUILDER).tab.* $(BUILDER_DIR)/lex.yy.*
	
# Suppression Executable et Binaries
mrproper: clean
	rm -f $(OUT) 
	



	
	


